﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Lor;


namespace ExpenseSystem.Fether
{
    public class ProductionFetcher : NormalFetcher<ProductionModel>
    {
        public ProductionModel GetByCode(long site, string code, out string message)
        {
            IList<ProductionModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("Code", code).And(Restrain.Eq("Avaliable", true)));
            if (result.Count > 0)
                return result.First();
            return null;
        }
        public IList<ProductionModel> ListByKeyword(long site, string keyword, out string message,out int rows)
        {
            Restrain restrain = Restrain.Or(
                    Restrain.Or(Restrain.Lk("Code", "%" + keyword + "%"), Restrain.Lk("Name", "%" + keyword + "%")),
                    Restrain.Lk("Specification", "%" + keyword + "%"));
            IList<ProductionModel> result = List( site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, restrain.And(Restrain.Eq("Avaliable", true)));
            return result;
        }

        public IList<ProductionModel> ListBySeries(long site,long series,out string message,out int rows)
        {
            IList<ProductionModel> result = List(site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("SeriesId",series));
            return result;
        }

        public IList<ProductionModel> ListByType(long site, long type, out string message,out int rows)
        {
            IList<ProductionModel> result = List(site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("ProductionTypeId", type));
            return result;
        }
        public IList<ProductionModel> ListByBland(long site, long bland, out string message,out int rows)
        {
            IList<ProductionModel> result = List(site, OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("BlandId", bland));
            return result;
        }

    }
}
